#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>

#include <linux/hdreg.h>
#include <linux/blkdev.h>
#include <linux/completion.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/mutex.h>
#include <linux/skbuff.h>
#include <linux/export.h>

//明天再实现真正的函数

#define 	Major 		100				//主设备号
#define 	DevName		"hello"			//设备名字

/* 文件操作函数的声明 */
static int file_open(struct inode *inode, struct file *filp);

static int file_release(struct inode *inode, struct file *filp);

static ssize_t file_write(struct file *file, const char __user *buffer,
			  size_t count, loff_t *ppos);

static ssize_t file_read(struct file *file, char __user *buffer, size_t count,
			 loff_t *ppos);


/* 驱动结构体 */
const struct file_operations hello_fops = {
	.owner =   THIS_MODULE,
	.open =    file_open,
	.release = file_release,
	.write =   file_write,
	.read =    file_read,
};

/* 实现打开文件 */
static int file_open(struct inode *inode, struct file *filp)
{
	return 0;
}

/* 实现关闭文件 */
static int file_release(struct inode *inode, struct file *filp)
{
	return 0;
}

/* 实现写文件 */
static ssize_t file_write(struct file *file, const char __user *buffer,
			  size_t count, loff_t *ppos)
{
    return 0;
}

/* 实现读文件 */
static ssize_t file_read(struct file *file, char __user *buffer, size_t count,
			 loff_t *ppos)
{
    return 0;
}


/* 驱动初始化 */
static int __init hello_init(void)
{
	int ret=0;
    printk(KERN_EMERG "[ KERN_EMERG ]  Hello  Module Init\n");
    ret=register_chrdev(Major,DevName,&hello_fops);				//注册驱动
	if(ret<0){													//驱动注册失败
		printk(KERN_EMERG "[ KERN_EMERG ]  Module init failed\n");	
		return ret;
	}
    return 0;
}

/* 卸载驱动 */
static void __exit hello_exit(void)
{
    printk("[ default ]   Hello  Module Exit\n");
	unregister_chrdev(Major, DevName);
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_LICENSE("GPL2");
MODULE_AUTHOR("embedfire ");
MODULE_DESCRIPTION("hello module");
MODULE_ALIAS("test_module");



